// smartclass/pages/addbuildingPage/addbuildingPage.js
const _wx = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: "",
    type:0,
    floornum:1,
    adminlist:[],
    resultnick: [],
    show: false,
    showPicker: false,
    fieldValue: "",
    columns: [{
        text: "男生宿舍",
        value: 1
      },
      {
        text: "女生宿舍",
        value: 2
      },
      {
        text: "混合宿舍",
        value: 3
      },
    ],
    result: ['a', 'b'],
    resultweek: ['a'],
    fieldValue2: "",
    currentDate: "",
    fieldValue3: "",
    currentDate3: "",
    radio: '1',
    radio2: "1"
  },
  onChanges(event) {
    this.setData({
      radio: event.detail,
    });
  },
  onChangese(event) {
    this.setData({
      radio2: event.detail,
    });
  },
  onChangenick(event) {
    // this.setData({this.data.resultnick:this.data.resultnick.push(event.detail[0])})
    // this.setData({
    //   resultnick: event.detail,
    // });
    // console.log(event.detail[0]);
    // this.setData({
    //   resultnick: event.detail,
    // });
    // this.setData({this.data.resultnick:this.data.resultnick.push(event.detail[0])})
    console.log(event.detail);
  },
  onChangeweek(event) {
    this.setData({
      resultweek: event.detail,
    });
  },
  confirms(event) {
    this.setData({
      shows: false
    })
    console.log(event.detail);
    this.setData({
      currentDate: event.detail,
    });
    this.setData({
      fieldValue2: event.detail
    })
    this.setData({
      shows: false
    })

  },
  confirms3(event) {
    this.setData({
      shows3: false
    })
    console.log(event.detail);
    this.setData({
      currentDate3: event.detail,
    });
    this.setData({
      fieldValue3: event.detail
    })
    this.setData({
      shows3: false
    })

  },
  onClick() {
    this.setData({
      shows: true,
    });
  },
  onClick3() {
    this.setData({
      shows3: true,
    });
  },
  shows: false,
  shows3: false,
  onClick2() {
    this.setData({
      shows: true
    })
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  onChange(event) {
    this.setData({
      result: event.detail,
    });
  },
  onConfirm(selectedOptions) {
    this.setData({
      showPicker: false
    })
    this.setData({
      fieldValue: selectedOptions.detail.value.text
    })
    this.setData({type:selectedOptions.detail.value.value})
  },
  onCancel() {
    this.setData({
      showPicker: false
    })
  },
  notification() {
    this.setData({
      showPicker: true
    })
  },
  handleshow() {
    this.setData({
      show: true
    })
  },
  buildinginsert() {
    const that = this
    _wx.getData('admin/dorm/dormbuilding/insert', 'POST', {
      name: this.data.username,
      start_time: result2.value,
      end_time: result3.value,
      status: checked1.value,
      monthdata: result4.value.toString(),
      weekdaydata: result5.value.toString(),
      admin_ids: suguanlistdata.value.toString(),
      floor_total: this.data.floornum,
      type:this.data.type,
      state: checked.value,
    }, function (res) {
      if (res.code == 0) {
        Toast.success('添加成功');
        setTimeout(function () {
          wx.redirectTo({
            url: '../buildingManger/buildingManger',
          })
        }, 2000);
      }
    });
  },
  noneedauthadmins(){
    const that = this
    _wx.getData('admin/dorm/noneedauth/admins', 'GET', {
    }, function (res) {
      if (res.code == 0) {
       that.setData({adminlist:res.data})
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.noneedauthadmins()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})